const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
Page({
    data: {
        username: '',
        password: '',
        code: '',
        token: ''
    },

    username(e) {
        this.setData({
            username: e.detail.value // 更新数据
        });
    },
    password(e) {
        this.setData({
            password: e.detail.value // 更新数据
        });
    },
    navigateToNewPage: function () {
        //登入请求 47.111.115.82
        wx.request({
            url: 'http://47.111.115.82:8080/login', //仅为示例，并非真实的接口地址
            method: "POST",
            data: {
                username: this.data.username,
                password: this.data.password
            },
            header: {
                'content-type': 'application/json' // 默认值
            },
            success(res) {
                console.log(res.data.code)
                console.log(res.data.data)
                //账号密码正确
                if (res.data.code == 1) {
                    wx.setStorageSync('code', res.data.code)
                    wx.setStorageSync('user', res.data.data)
                    wx.setStorageSync('token', res.data.data.jwt)
                    wx.switchTab({
                        url: '/pages/video/video',
                    })
                } else {
                    this.setData({
                        username: '',
                        password: ''
                    })
                }
            }
        })

    },
    addUser() {
        wx.navigateTo({
            url: '/pages/addUser/addUser',
        })
    }
})